package com.collabscm.pf.util;

import java.io.IOException;

import net.sf.ehcache.CacheManager;

import org.junit.BeforeClass;
import org.junit.Test;

import com.collabscm.pf.BaseObject;
import com.collabscm.pf.cache.ehcache.EhcacheCacheManager;

/**
 * 测试JsonUtils
 * @author Zeng Raoxing
 */
public class TestJsonUtils {
	
	@BeforeClass
	public static void init() throws IOException {
		//先加载缓存
		CacheManager manager = CacheManager.create(TestJsonUtils.class.getResourceAsStream("ehcache.xml"));
		new EhcacheCacheManager(manager);
	}
	
	@Test
	public void testToJsonObjectString() throws Exception {
		ChildBaseObject cbo = new ChildBaseObject();
		cbo.setId("1");
		cbo.setName("2");
		System.out.println(JsonUtils.toJsonObjectString(cbo));
		OtherClass oc = new OtherClass();
		oc.setType("otherclass");
		oc.setObject(cbo);
		System.out.println(JsonUtils.toJsonObjectString(oc));
	}
	
	public static class ChildBaseObject extends BaseObject {
		private static final long serialVersionUID = 1L;
		private String id;
		private String name;
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		@Override
		public String toJSONString() {
			return "Hello。";
		}
	}
	
	public static class OtherClass {
		private String type;
		private ChildBaseObject object;
		public String getType() {
			return type;
		}
		public void setType(String type) {
			this.type = type;
		}
		public ChildBaseObject getObject() {
			return object;
		}
		public void setObject(ChildBaseObject object) {
			this.object = object;
		}
	}

}
